﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
/// <summary>
/// Sql 的摘要说明
/// </summary>
public class TSqlDB
{
    public TSqlDB()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    protected static string GetConnString()
    {


        string source = System.Web.HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["source"]);
        return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + source;



    }
    public static DataTable getDataTable(string sql)
    {



        OleDbConnection con = new OleDbConnection(GetConnString());


        OleDbCommand com = new OleDbCommand();


        com.Connection = con;
        com.CommandText = sql;
        OleDbDataAdapter ada = new OleDbDataAdapter();
        ada.SelectCommand = com;
        DataSet ds = new DataSet();
        ada.Fill(ds);
        com.Dispose();


        DataTable dt = new DataTable();
        dt = ds.Tables[0];
        return dt;


    }
    public static int ExecuteNonQuery(string Query)
    {
        int Result;

        OleDbConnection con = new OleDbConnection(GetConnString());
        con.Open();
        OleDbCommand com = new OleDbCommand(Query, con);
        Result = com.ExecuteNonQuery();
        con.Close();
        return Result;

    }
    public static object ExecuteAlone(string Query)
    {
        object Result;

        OleDbConnection con = new OleDbConnection(GetConnString());
        con.Open();

        OleDbCommand com = new OleDbCommand(Query, con);
        Result = com.ExecuteScalar();
        con.Close();

        return Result;
    }

}
